home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / daymisckit_proj / Examples / DAYLockFile / LockFileTest.m < prev    next >
Text File  |  1995-06-12  |  2KB  |  51 lines

  1. // LockFileTest.m -- test out the lock file class
  2.  
  3. #import <daymisckit/daymisckit.h>
  4. #import <appkit/appkit.h>
  5. #import <stdio.h>
  6.  
  7. void main()
  8. {
  9.     id lockFile1 = [[DAYLockFile alloc] init];
  10.     id lockFile2 = [[DAYLockFile alloc] init];
  11.  
  12.     printf("Standard lock/unlock test...");
  13.     [lockFile1 setFileName:[[DAYString alloc] initString:"lock1"]];
  14.     if (![lockFile1 lock]) { printf("failed on lock.\n"); exit(1); }
  15.     printf("\n");
  16.     system("ls -alsFg lock1");
  17.     system("cat lock1"); printf("\n");
  18.     if (![lockFile1 haveLock]) { printf("haveLock is wrong.\n"); exit(1); }
  19.     if (![lockFile1 unlock]) { printf("failed on unlock.\n"); exit(1); }
  20.     system("ls -alsFg lock1");
  21.     printf("passed.\n");
  22.  
  23.     printf("Attempt to obtain lock when someone else has it...");
  24.     [lockFile2 setFileName:[[DAYString alloc] initString:"lock1"]];
  25.     if (![lockFile1 lock]) { printf("failed on initial lock.\n"); exit(1); }
  26.     if ([lockFile2 lock]) { printf("second client got lock.\n"); exit(1); }
  27.     if (![lockFile1 haveLock]) { printf("haveLock #1 is wrong.\n"); exit(1); }
  28.     if ([lockFile2 haveLock]) { printf("haveLock #2 is wrong.\n"); exit(1); }
  29.     if (![lockFile1 unlock]) { printf("failed on unlock.\n"); exit(1); }
  30.     if ([lockFile2 unlock]) { printf("lock #2 unlocked.\n"); exit(1); }
  31.     printf("passed.\n");
  32.  
  33.     printf("Dual lock/unlock test...");
  34.     [lockFile1 setFileName:[[DAYString alloc] initString:"lock1"]];
  35.     [lockFile2 setFileName:[[DAYString alloc] initString:"lock2"]];
  36.     if (![lockFile1 lock]) { printf("failed on lock #1.\n"); exit(1); }
  37.     if (![lockFile2 lock]) { printf("failed on lock #2.\n"); exit(1); }
  38.     printf("\n");
  39.     system("ls -alsFg lock1 lock2");
  40.     system("cat lock1"); printf("\n");
  41.     system("cat lock2"); printf("\n");
  42.     if (![lockFile1 haveLock]) { printf("haveLock #1 is wrong.\n"); exit(1); }
  43.     if (![lockFile2 haveLock]) { printf("haveLock #2 is wrong.\n"); exit(1); }
  44.     if (![lockFile1 unlock]) { printf("failed on unlock #1.\n"); exit(1); }
  45.     if (![lockFile2 unlock]) { printf("failed on unlock #2.\n"); exit(1); }
  46.     system("ls -alsFg lock1 lock2");
  47.     printf("passed.\n");
  48.  
  49.     exit(0);
  50. }
  51.